home *** CD-ROM | disk | FTP | other *** search
/ Mac OS 9 Serial Number Archive / SN Archive 2023.11.04.toast / BSNG / SDK / BSNG SDK 2.6 / Libraries / standard utils / standard utils.h < prev   
Encoding:
C/C++ Source or Header  |  1998-02-05  |  7.3 KB  |  152 lines  |  [TEXT/CWIE]

  1. /*
  2.  * $Workfile:: standard utils.h                                               $
  3.  * $Revision:: 1                                                              $
  4.  *
  5.  * $Author:: Buck Rogers                                                      $
  6.  * $Modtime:: 30.09.1997 17:49 Uhr                                            $
  7.  *
  8.  * $History:: standard utils.h                                                $
  9.  * 
  10.  * *****************  Version 1  *****************
  11.  * User: Buck Rogers  Date: 30.09.1997   Time: 18:31 Uhr
  12.  * Created in $/BSNG/Plugins/BSNG SDK/Libraries/standard utils
  13.  * Adding subproject 'BSNG' to '$/'
  14.  *
  15.  * $NoKeywords::                                                              $
  16.  */
  17.  
  18.  
  19. #pragma once
  20.  
  21.  
  22. #define LSN(A)             ((A)&0x0000000F)
  23. #define MSN(A)            (((A)&0x000000F0)>>4)
  24. #define LSB(A)             ((A)&0x000000FF)
  25. #define MSBLoWord(A)    (((A)&0x0000FF00)>>8)
  26. #define LSBHiWord(A)    (((A)&0x00FF0000)>>16)
  27. #define MSB(A)            (((A)&0xFF000000)>>24)
  28.  
  29.  
  30. typedef unsigned char Str3[4];
  31. typedef unsigned char Str4[5];
  32. typedef unsigned char Str8[9];
  33.  
  34.  
  35. // RANDOM NUMBER/STRING GENERATION UTILITIES
  36.                        
  37. Boolean            myBooleanRandom            (void);
  38. unsigned short    myShortRangedRandom        (unsigned short min,unsigned short max);
  39. unsigned long    myLongRangedRandom        (unsigned long  min,unsigned  long max);
  40. void            myBaseBRandomPStr        (Str255       s,unsigned short b,unsigned short numDigits);
  41. void            myBaseBRandomDigits        (StringPtr s,unsigned short b,unsigned short numDigits);
  42. void            mySFBaseBRandomPStr        (Str255       s,unsigned short b,unsigned short numSigDigits);
  43. void            mySFBaseBRandomDigits    (StringPtr s,unsigned short b,unsigned short numSigDigits);
  44. unsigned char    myRandom09Char            (void);
  45. unsigned char    myRandomAZChar            (void);
  46. unsigned char    myRandom09AZChar        (void);
  47.  
  48. // INTEGER/WHOLE NUMBER MATHEMATICAL/MANIPULATION ROUTINES
  49.  
  50. unsigned long    myABSL        (signed long    n);
  51. unsigned short    myABSW        (signed short    n);
  52. unsigned char    myArithROLB    (unsigned char    n,unsigned short b);                            // similar to myROLB but shifting is done arithmetically and we EOR instead of OR
  53. unsigned char    myArithRORB    (unsigned char    n,unsigned short b);                            // similar to myRORB but shifting is done arithmetically and we EOR instead of OR
  54. unsigned char    myROLB        (unsigned char    n,unsigned short b);                            // Rotate 8 bit value n, b bits to the left
  55. unsigned char    myRORB        (unsigned char    n,unsigned short b);                            // Rotate 8 bit value n, b bits to the right
  56. unsigned short    myROLW        (unsigned short    n,unsigned short b);                            // Rotate 16 bit value n, b bits to the left
  57. unsigned short    myRORW        (unsigned short    n,unsigned short b);                            // Rotate 16 bit value n, b bits to the right
  58. unsigned long    myROLL        (unsigned long    n,unsigned short b);                            // Rotate 32 bit value n, b bits to the left
  59. unsigned long    myROLLByteX    (unsigned long    n,unsigned short theByte,unsigned short b);
  60. unsigned long    myROLLWordX    (unsigned long    n,unsigned short theWord,unsigned short b);
  61. unsigned long    myRORL        (unsigned long    n,unsigned short b);                            // Rotate 32 bit value n, b bits to the right
  62. unsigned long    myRORLByteX    (unsigned long    n,unsigned short theByte,unsigned short b);
  63. unsigned long    myRORLWordX    (unsigned long    n,unsigned short theWord,unsigned short b);
  64.  
  65. unsigned long    myIntegerSquareRoot(unsigned long n);                                        // extremely poor algorithm
  66. unsigned long    myClosestIntegerSquareRoot(unsigned long n);                                // extremely poor algorithm
  67.  
  68.  
  69. // NUMERIC STRING and NUMBER <--> STRING ROUTINES
  70.  
  71. unsigned short    myBaseXCharToVal    (unsigned char c);                                        // c should be 0..9, A..Z, a..z
  72.  
  73. long            myPStrToNum            (const Str255     s);
  74. long            myCharsToNum        (const StringPtr s,unsigned short numDigits);
  75. long            myDigitsToNum        (const StringPtr s,unsigned short numDigits);
  76. long            myBaseBPStrToNum     (const Str255     s,unsigned short b);
  77. long            myBaseBDigitsToNum    (const StringPtr s,unsigned short b,unsigned short numDigits);
  78.  
  79. void            myZeroPadPStr        (Str255 s,unsigned short paddedLength);
  80. unsigned char    myValToBaseXChar     (unsigned short v);
  81. void            mySNumToPStr        (          long n,Str255    s,unsigned short minDigits);
  82. void            myUNumToPStr        (unsigned long n,Str255    s,unsigned short minDigits);
  83. void            myUNumToBaseBPStr    (unsigned long n,Str255       s,unsigned short b,unsigned short minDigits);
  84. unsigned short    myUNumToDigits        (unsigned long n,StringPtr s,unsigned short minDigits);    
  85. unsigned short    myUNumToBaseBDigits    (unsigned long n,StringPtr s,unsigned short b,unsigned short minDigits);
  86.  
  87. unsigned long    mySumOfPStr              (const Str255 s);                                        // does not include the length byte
  88. unsigned long    myIndexWeightedSumOfPStr(const Str255 s);                                    // does not include the length byte
  89. unsigned long    mySumOfChars        (const StringPtr s,unsigned short numChars);
  90. unsigned long    mySumOfBaseXPStr      (const Str255 s);                                        // does not include the length byte
  91. unsigned long    mySumOfBaseXDigits    (const StringPtr s,unsigned short numDigits);
  92.  
  93. unsigned long    my4BytesAsUNum        (const StringPtr s);                                    // gets unsigned value of the 4 bytes at *s
  94. unsigned long    my2BytesAsUNum        (const StringPtr s);                                    // gets unsigned value of the 2 bytes at *s
  95.  
  96. // STRING MANIPULATION ROUTINES
  97.  
  98. unsigned long    cStrLen(const Ptr s,unsigned long maxLen);
  99. void            myCStrToPStr(unsigned char *s);
  100.  
  101. void             myCopyPStr                (const Str255 orig,Str255 copy);
  102. Boolean            myEqualPStr                (const Str255 s,const Str255 t);
  103.  
  104. short            myFindFirstInPStr        (const Str255 s,unsigned char c);                    // returns 0 iff c is not in s
  105. short            myFindLastInPStr        (const Str255 s,unsigned char c);                    // returns 0 iff c is not in s
  106.  
  107. void             myGetPStrSubString        (const Str255 s,short offset,unsigned short numChars,Str255 subStr);
  108. void            myPrefixPStr            (Str255 s,const Str255 prefixStr);
  109. void            myAppendPStr            (Str255 s,const Str255 suffixStr);
  110. void            myAppendCharToPStr        (Str255 s,unsigned char c);
  111. void            myAppendQuotedPStr        (Str255 s,const Str255 suffixStr);
  112. void            myInsertInPStr            (Str255 s,const Str255 insertStr,short offset);        // does an 'insert before'
  113. void             myBracketPStrWithChar    (Str255 s,unsigned char c,signed short numBefore,signed short numAfter);
  114. void            myUnBracketPStrWithChar    (Str255 s,unsigned char c,Boolean doBefore,Boolean doAfter);
  115. void            myStripCharFromPStr        (Str255 s,unsigned char c);
  116. void            myDeleteElementFromPStr    (Str255 s,unsigned short index);
  117.  
  118. void             myUpCasePStr            (Str255 s);
  119. void             myLoCasePStr            (Str255 s);
  120. void             myTitleCasePStr            (Str255 s);
  121. void            myTruncatePStr            (Str255 s,unsigned short maxLength);
  122. void             myReversePStr            (Str255 s);
  123.  
  124. void             myMapPStr                (Str255 s,unsigned short *mapIndexes);
  125. void            myInversePermutatePStr    (Str255 s,unsigned short *permIndexes);
  126.  
  127.  
  128. // RESOURCE ROUTINES
  129.  
  130. Boolean        mySaveResource    (const Handle theResource);
  131.  
  132.  
  133. // STANDARD FILE ROUTINES
  134.  
  135. Boolean        myPutFile        (FSSpec *theFSSPtr,OSType type,OSType creator,const Str255 prompt,const Str255 defaultName);
  136. Boolean        myGetFile        (FSSpec *theFSSPtr);
  137.  
  138.  
  139. // FILE ROUTINES 
  140.  
  141. OSErr        myCloseFile        (short *fileRefNum,FSSpec *fileFSSpec);
  142. OSErr        myOpenResFile    (FSSpec *inputFSSPtr,short permission,short *inputRefNumPtr);
  143.  
  144.  
  145. // TEXT FILE OUTPUT ROUTINES
  146.  
  147. void    myOutputPStr            (short outputRefNum,const Str255 s);
  148. void    myOutputSuffixedPStr    (short outputRefNum,const Str255 s,const Str255 suffixStr);
  149. void    myOutputText            (short outputRefNum,const Ptr TextPtr,unsigned long textLen);
  150. void    myOutputSuffixedText    (short outputRefNum,const Ptr TextPtr,unsigned long textLen,const Str255 suffixStr);
  151. void    myOutputResHeader        (short outputRefNum,OSType theType,short theID,const Str255 theName);
  152.